1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : news/classes/class.NewsCategoryLiterature.inc.php
5 : - Modulgruppe: News
6 : - Beschreibung: Klasse für die News-Kategorie Literatur.
7 : - Version: 1.1.2.4, 24/01/08
8 : - Autor(en): Corinna Kropf <corinna.kropf@mni.fh-giessen.de>
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 :
24 1 : require_once ("class.newscategory.inc.php");
25 :
26 : /**
27 : * Klasse für die News-Kategorie Literatur.
28 : * @package eStudy.News
29 : * @version 1.1.2.4, 24/01/08
30 : * @author Corinna Kropf <corinna.kropf@mni.fh-giessen.de>
31 : */
32 1 : class NewsCategoryLiterature extends NewsCategory
33 : {
34 : /**
35 : * Cache Objekt zur Abfrage von Modulinstallationen (Performance Tweak)
36 : * @var array
37 : */
38 : private $installCacheObject;
39 : /**
40 : * Flag fuer die Anzeige der News-Eintraege
41 : * @var bool
42 : */
43 : private $dark;
44 : /**
45 : * HTML-Template
46 : * @var Template
47 : */
48 : private $newsTemplate;
49 : /**
50 : * HTML-Template
51 : * @var Template
52 : */
53 : private $commentTemplate;
54 : /**
55 : * HTML-Template
56 : * @var Template
57 : */
58 : private $newCommentTemplate;
59 : /**
60 : * Konstruktor
61 : */
62 : public function __construct($catID, $courses, $categorySettings = null, $cacheObject = null)
63 : {
64 0 : parent::__construct($catID, $courses, $categorySettings);
65 0 : $this->installCacheObject = $cacheObject;
66 0 : $this->newsTemplate = new Template(PATH_TO_ROOT."news/templates/newsliterature.html");
67 0 : $this->commentTemplate = new Template(PATH_TO_ROOT."news/templates/newsliteraturecomment.html");
68 0 : $this->newCommentTemplate = new Template(PATH_TO_ROOT."news/templates/newsliterature_newcomment.html");
69 0 : }
70 : /**
71 : * Überschreibt die Methode der Oberklasse,
72 : * um weitere Initialisierungen vor der Ausgabe zu machen.
73 : * @see NewsCategory
74 : */
75 : public function echoNews($courseID, $usergroup = null)
76 : {
77 0 : $this->dark = false;
78 0 : parent::echoNews($courseID, $usergroup);
79 0 : }
80 : /**
81 : * Muss angepasst werden, falls Modulgruppen umbenannt werden!
82 : * @see NewsCategory
83 : */
84 : public function isInstalled($courseID)
85 : {
86 0 : return Utilities::isInstalled("literatur", $courseID, $this->installCacheObject);
87 : }
88 : /**
89 : * @see NewsCategory
90 : */
91 : public function canSelectPeriod() {
92 0 : return true;
93 : }
94 : /**
95 : * @see NewsCategory
96 : */
97 : public function getNewsHeaderTitle($courseID = null, $type = null) {
98 0 : if(isset($this->news["count"]) && $this->news["count"]>0)
99 0 : {
100 0 : $newsCount = $this->news["count"];
101 0 : if ( $newsCount == 1 ) $title = $this->translate->_("1 Literaturempfehlung");
102 0 : else if ( $newsCount > 1 ) $title = sprintf( $this->translate->_("%1\$s Literaturempfehlungen"), $newsCount);
103 0 : }
104 0 : else $title = $this->translate->_("Keine neuen Literaturempfehlungen");
105 :
106 0 : return $title;
107 : }
108 :
109 : public function createQueryCacheObject($lastvisit, $usergroup) {
110 0 : global $db;
111 :
112 0 : $userID = data::toMysql($_SESSION["userid"]);
113 : // Alle Kurse des Benutzers
114 0 : if ($usergroup != ADMIN) {
115 : $sql = "SELECT courseID FROM user_course JOIN courses ON courseID=ID "
116 0 : ."WHERE userID='$userID' AND closed='0' UNION SELECT 0 as courseID"; // Foyer miteinschließen
117 0 : } else {
118 0 : $sql = "SELECT ID AS courseID FROM courses WHERE closed = 0 UNION SELECT 0 as courseID";
119 : }
120 0 : $courseResult = $db->get_col($sql);
121 0 : $courseList = implode(",", $courseResult);
122 0 : $courseList = data::toMysql($courseList);
123 :
124 0 : $lastVisitTime = date("Y-m-d H:i:s", $this->getPeriod(0, $lastvisit) );
125 0 : $this->queryCacheObject = array();
126 0 : $this->queryCacheObject[-1] = "cacheFlag";
127 : $sql = "SELECT courseID FROM booklits "
128 : ."WHERE littype='B' "
129 0 : ."AND Time >= '" . $lastVisitTime . "' "
130 0 : ."AND courseID IN ($courseList) "
131 0 : ."GROUP BY courseID ORDER BY Time DESC";
132 0 : $res = $db->get_results($sql);
133 0 : if ($res != null) {
134 0 : foreach ($res as $course)
135 0 : $this->queryCacheObject[$course->courseID] = "newEntries";
136 0 : }
137 :
138 : $sql = "SELECT *, booklits.courseID FROM booklinks,booklits "
139 : ."WHERE booklits.litid=booklinks.litid "
140 0 : ."AND booklits.littype='L' "
141 0 : ."AND Time >= '" . $lastVisitTime . "' "
142 0 : ."AND courseID IN ($courseList) "
143 0 : ."GROUP BY courseID ORDER BY Time DESC";
144 0 : $res = $db->get_results($sql);
145 0 : if ($res != null) {
146 0 : foreach ($res as $course)
147 0 : $this->queryCacheObject[$course->courseID] = "newEntries";
148 0 : }
149 :
150 : $sql = "SELECT bookcomments.*, booklits.courseID, LitType as LitTyp, CourseID FROM bookcomments, booklits "
151 : ."WHERE booklits.id=bookcomments.litid "
152 0 : ."AND bookcomments.Time >= '" . $lastVisitTime . "' "
153 0 : ."AND courseID IN ($courseList) "
154 0 : ."GROUP BY courseID ORDER BY bookcomments.Time DESC";
155 0 : $res = $db->get_results($sql);
156 0 : if ($res != null) {
157 0 : foreach ($res as $course)
158 0 : $this->queryCacheObject[$course->courseID] = "newEntries";
159 0 : }
160 0 : }
161 :
162 : /**
163 : * @see NewsCategory
164 : */
165 : protected function getNewsByPeriod($courseID, $from, $to, $lastvisit, $usergroup = null) {
166 :
167 0 : $this->news = null;
168 :
169 : // Da die Literatursuche sehr Aufwändig ist werden in den Query Cache nur Kurs-IDs gelistet,
170 : // in denen es neue Literatureinträge gibt. Es werden also nicht alle Daten gecached,
171 : // die Datenbank Abfragen werden jedoch auf die Kurse minimiert, in denen es
172 : // tatsächlich neue Literatureinträge gibt
173 0 : if ($_SESSION["course"] == 0 || $this->queryCacheObject != null) {
174 0 : if ($this->queryCacheObject == null) {
175 0 : $this->createQueryCacheObject($lastvisit, $usergroup);
176 0 : }
177 0 : if ($this->queryCacheObject == null)
178 0 : return null;
179 :
180 : // Keine neue Literatur im Kurs, also Kurs überspringen
181 0 : if (!array_key_exists($courseID, $this->queryCacheObject))
182 0 : return null;
183 0 : }
184 :
185 0 : if (isset($courseID) && isset($lastvisit) && isset($this->coursePreferences))
186 0 : {
187 0 : if(!is_numeric($courseID) || !is_numeric($lastvisit)) return null;
188 :
189 0 : global $db;
190 0 : $this->news = array();
191 : /*
192 : * Folgendes Problem: Die Sortierung der Literatureintraege ist
193 : * recht ausgekluegelt. Um dennoch herauszufinden, auf welcher
194 : * Seite im Literaturmodul die Buecher und Links dargestellt werden,
195 : * wird zunaechst die Seite in einem Array simuliert. Daraus laesst
196 : * sich dann die Seitenzahl ablesen, wo die Eintraege stehen.
197 : */
198 0 : if ( $courseID == 0 ) {
199 0 : $group = "SELECT Usergroup FROM user WHERE ID = bc.UserID";
200 0 : } else {
201 : $group = "SELECT IF(differentUsergroup>0, differentUsergroup, Usergroup) AS Usergroup "
202 : ."FROM user LEFT JOIN user_course ON ID=userID "
203 0 : ."WHERE ID=bc.UserID "
204 0 : ."AND courseID='".Data::toMysql($courseID)."'";
205 : }
206 :
207 0 : $sql = "SELECT *, ($group) AS UserGroup "
208 : ."FROM books as b, booklits as bc "
209 0 : ."WHERE b.litid = bc.litid "
210 0 : ."AND bc.littype='B' AND bc.courseid = '".Data::toMysql($courseID)."'";
211 :
212 0 : $books = $db->get_results( $sql );
213 0 : $this->news["totalbookcount"] = $db->num_rows;
214 :
215 0 : $sql = "SELECT *, ($group) AS UserGroup "
216 : ."FROM booklits as bc, booklinks as bl "
217 0 : ."WHERE bl.litid=bc.litid "
218 0 : ."AND bc.littype='L' "
219 0 : ."AND courseid='".Data::toMysql($courseID)."'";
220 0 : $links = $db->get_results($sql);
221 0 : $this->news["totalbookcount"] += $db->num_rows;
222 0 : $this->news["allbooks"] = (is_array($books) && is_array($links)) ? array_merge( $books, $links ) : null;
223 0 : if ( is_array($this->news["allbooks"]) ) {
224 0 : usort($this->news["allbooks"], array ("NewsCategoryLiterature", "literatureCompare") );
225 0 : }
226 0 : $lastVisitTime = date("Y-m-d H:i:s", $this->getPeriod($courseID, $lastvisit) );
227 :
228 : // Buecher laden
229 : $sql = "SELECT * FROM booklits "
230 : ."WHERE littype='B' "
231 0 : ."AND Time >= '" . $lastVisitTime . "' "
232 0 : ."AND CourseID = '".Data::toMysql($courseID)."' "
233 0 : ."ORDER BY Time DESC";
234 0 : $this->news["data"] = $db->get_results( $sql, ARRAY_A );
235 :
236 0 : $this->news["count"] = 0;
237 0 : if ( $db->num_rows == 0) ; //$this->news = null;
238 : else {
239 0 : $this->news["count"] = $db->num_rows;
240 : // Informationen und Kommentare ueber das Buch laden
241 0 : for ( $i=0; $i<count($this->news["data"]); $i++ ) {
242 0 : $sql = "SELECT Title, Author FROM books WHERE LitID = '" . $this->news["data"][$i]['LitID'] . "'";
243 0 : $lit = $db->get_row( $sql );
244 0 : $lit->ID = $this->news["data"][$i]['ID'];
245 0 : $userID = $this->news["data"][$i]["UserID"];
246 : //$this->news["data"][$i]['ID'] = $lit->ID;
247 0 : $this->news["data"][$i]['Title'] = $lit->Title;
248 0 : $this->news["data"][$i]['Author'] = $lit->Author;
249 0 : $this->news["data"][$i]['Type'] = 'Book';
250 0 : $this->news["data"][$i]['Page'] = self::literaturePageNum( self::literaturePosition( $this->news["allbooks"], $lit->ID, 'B' ) );
251 0 : $this->users[$userID] = $userID;
252 0 : }
253 : }
254 :
255 : // Links laden
256 : $sql = "SELECT * FROM booklinks,booklits "
257 : ."WHERE booklits.litid=booklinks.litid "
258 0 : ."AND booklits.littype='L' "
259 0 : ."AND Time >= '" . $lastVisitTime . "' "
260 0 : ."AND CourseID = '".Data::toMysql($courseID)."' "
261 0 : ."ORDER BY Time DESC";
262 0 : $result = $db->get_results( $sql, ARRAY_A );
263 0 : if ( $db->num_rows == 0 ) ; //$this->news = null;
264 0 : else if ( $db->num_rows > 0 ){
265 0 : foreach( $result as $res ) {
266 0 : $this->news["data"][] = $res;
267 0 : }
268 : // Informationen und Kommentare ueber den Link laden
269 0 : for ( $i=$this->news["count"]; $i<count($this->news["data"]); $i++ ) {
270 0 : $userID = $this->news["data"][$i]["UserID"];
271 0 : $this->news["data"][$i]['Type'] = 'Link';
272 0 : $this->news["data"][$i]['Page'] = self::literaturePageNum( self::literaturePosition( $this->news["allbooks"], $this->news["data"][$i]['ID'], 'L' ) );
273 0 : $this->users[$userID] = $userID;
274 0 : }
275 0 : $this->news["count"] += $db->num_rows;
276 0 : }
277 : // Das zusammengefuehrte Array nach dem Datum sortieren, neustes zuerst
278 0 : if ( isset($this->news["data"]) && is_array($this->news["data"]) ) {
279 0 : usort($this->news["data"], array( "NewsCategoryLiterature", "literatureSort" ) );
280 0 : }
281 : // Kommentare laden
282 : $sql = "SELECT bookcomments.*, LitType as LitTyp, CourseID FROM bookcomments, booklits "
283 : ."WHERE booklits.id=bookcomments.litid "
284 0 : ."AND bookcomments.Time >= '" . $lastVisitTime . "' "
285 0 : ."AND CourseID = '".Data::toMysql($courseID)."' "
286 0 : ."ORDER BY bookcomments.Time DESC";
287 0 : $this->news["comments"] = $db->get_results( $sql, ARRAY_A );
288 0 : if ( $db->num_rows == 0) unset( $this->news["comments"] );
289 : else {
290 0 : $this->news["count"] += $db->num_rows;
291 0 : for ( $i=0; $i<count($this->news["comments"]); $i++ ) {
292 0 : $litexists = false;
293 0 : $foundkey = 0;
294 : /*
295 : * Der folgende Abschnitt sucht in dem Array der bisher
296 : * geladenen Literatur nach Eintraegen, fuer die die
297 : * Kommentare bestimmt sind. Die Idee ist, dass die Literatur
298 : * als Unterarray ihre Kommentare beinhaltet. Wird hier
299 : * nichts gefunden, wird die Literatur nachgeladen.
300 : */
301 0 : if ( isset($this->news["data"]) ) {
302 0 : foreach( $this->news["data"] as $key1 => $litlist ) {
303 0 : if ( $litexists ) break;
304 :
305 0 : foreach( $litlist as $key2 => $val ) {
306 0 : if ( $litexists ) break;
307 0 : $type = ($this->news["comments"][$i]['LitTyp'] == 'B') ? "Book" : "Link";
308 0 : if ( $key2 === "ID" && $this->news["data"][$key1]['Type'] == $type ) {
309 0 : if ( $val === $this->news["comments"][$i]["LitID"] ) {
310 0 : $litexists = true;
311 0 : $foundkey = $key1;
312 0 : break;
313 : }
314 0 : }
315 0 : }
316 0 : }
317 0 : }
318 : $sql = "SELECT bookcomments.*, LitType as LitTyp, CourseID FROM bookcomments, booklits "
319 : ."WHERE booklits.id=bookcomments.litid "
320 0 : ."AND booklits.ID = '" . $this->news["comments"][$i]['LitID'] . "' "
321 0 : ."ORDER BY bookcomments.Time";
322 0 : $comments = $db->get_results( $sql );
323 0 : $commentcount = $db->num_rows;
324 0 : if ( $litexists ) {
325 0 : $type = ($this->news["data"][$foundkey]['Type'] == "Book") ? 'B' : 'L';
326 0 : $this->news["comments"][$i]["CommentPage"] = self::literaturePageNum( self::literatureCommentPosition( $comments, $this->news["comments"][$i]['ID'], $type ), 5 );
327 : // Bereits erfasste Literatur um die neuen Kommentare ergaenzen
328 0 : if ( $type === (string)$this->news["comments"][$i]["LitTyp"] ) {
329 0 : $this->news["data"][$foundkey]["Comments"][] = $this->news["comments"][$i];
330 0 : $userID = $this->news["comments"][$i]["UserID"];
331 0 : $this->users[$userID] = $userID;
332 0 : }
333 0 : } else {
334 : // Es gibt nur Kommentare zu aelteren Literatureintraegen
335 0 : if ( $this->news["comments"][$i]['LitTyp'] == 'B' ) {
336 : // Buecher
337 : $sql = "SELECT ID, Title, Author FROM books,booklits "
338 : ."WHERE books.litid=booklits.litid "
339 0 : ."AND littype='B' "
340 0 : ."AND ID = '" . $this->news["comments"][$i]['LitID'] . "'";
341 0 : $lit = $db->get_row( $sql, ARRAY_A );
342 0 : $litinfo = $lit;
343 0 : $litinfo['Type'] = "Book";
344 0 : $sql = "SELECT * FROM booklits WHERE ID = '" . $lit['ID'] . "' AND CourseID = '".Data::toMysql($courseID)."'";
345 0 : $lit = $db->get_row( $sql, ARRAY_A );
346 0 : foreach( $lit as $key => $val ) {
347 0 : $litinfo[$key] = $val;
348 0 : }
349 0 : } else {
350 : // Links
351 : $sql = "SELECT * FROM booklinks, booklits "
352 : ."WHERE booklinks.litid=booklits.litid "
353 0 : ."AND littype='L' "
354 0 : ."AND ID = '" . $this->news["comments"][$i]['LitID'] . "'";
355 0 : $lit = $db->get_row( $sql, ARRAY_A );
356 0 : $litinfo = $lit;
357 0 : $litinfo['Type'] = "Link";
358 : }
359 0 : $userID = $this->news["comments"][$i]["UserID"];
360 0 : $this->users[$userID] = $userID;
361 0 : $this->users[$litinfo["UserID"]] = $litinfo["UserID"];
362 0 : $type = ($litinfo['Type'] == "Book") ? 'B' : 'L';
363 0 : $litinfo["Page"] = self::literaturePageNum( self::literaturePosition( $this->news["allbooks"], $litinfo["ID"], $type ) );
364 0 : $this->news["comments"][$i]["CommentPage"] = self::literaturePageNum( self::literatureCommentPosition( $comments, $this->news["comments"][$i]['ID'], $type ), 5 );
365 : // Die zugehoerige Literatur wird nicht als "neu" auf
366 : // der Startseite erscheinen, nur als Zusatzinformation
367 0 : $litinfo["Old"] = true;
368 : // litinfo haelt die alle benoetigen Literaturinfos
369 : // Hier werden die Kommentare der Literatur zugeordnet
370 0 : $litinfo["Comments"][] = $this->news["comments"][$i];
371 : // Anschliessend wird litinfo in seinen endgueltigen
372 : // Behaelter kopiert
373 0 : $this->news["comments"][$i] = $litinfo;
374 0 : $this->news["data"][] = $this->news["comments"][$i];
375 : }
376 0 : }
377 : }
378 0 : }
379 :
380 0 : if(!isset($this->news["count"]) || $this->news["count"] == 0) $this->news = null;
381 :
382 0 : return $this->news;
383 : }
384 : /**
385 : * @see NewsCategory
386 : */
387 : protected function echoNewsEntry($entry, $courseID, $usergroup = null)
388 : {
389 0 : if(!isset($this->dark) || !isset($entry) || !isset($courseID) || !isset($this->news["user"])) return;
390 :
391 0 : $id = $entry['ID'];
392 0 : $getvars = "?bookpage=" . $entry["Page"];
393 0 : $getvars .= isset($entry["Comments"]) ? "&showcomments=$id&littyp=" . $entry['Type'] : "";
394 0 : $getvars .= ($courseID && $courseID != $_SESSION["course"]) ? "&changeToCourse=$courseID" : "";
395 0 : $url = PATH_TO_ROOT."literatur/literatur.php$getvars#Book".$id;
396 0 : $title = Data::toHTML( $entry["Title"] . " - " . $entry["Author"], false );
397 :
398 0 : $g_ZurLiteraturseite = $this->translate->_("Zur Literaturseite");
399 0 : $g_Empfehlunglesen = $this->translate->_("Empfehlung lesen");
400 0 : $g_Lesen = $this->translate->_("Lesen");
401 :
402 0 : eval($this->newsTemplate->GetTemplate());
403 0 : if ( ! isset( $entry["Old"] ) ) {
404 : // Diese Literaturempfehlung wurde neu hinzugefuegt
405 0 : $userLink = $this->getProfileLink($this->news["user"], $entry["UserID"], $courseID);
406 0 : $commentTime = Output::echoDate("d.m.Y H:i", $entry["Time"]);
407 0 : $shortComment = Data::toHTML(Utilities::chopText($entry["Comment"], 140), false);
408 0 : $lesen = "<a href='$url' title='Empfehlung lesen'>Lesen</a>";
409 :
410 0 : eval($this->newCommentTemplate->GetTemplate());
411 0 : }
412 0 : if ( isset($entry["Comments"]) ) {
413 0 : foreach( $entry["Comments"] as $com ) {
414 0 : $userLink = $this->getProfileLink($this->news["user"], $com["UserID"], $courseID);
415 0 : $comment = Data::toHTML(Utilities::chopText($com["Comment"], 140), false);
416 0 : $commentTime = Output::echoDate("d.m.Y H:i", $com["Time"]);
417 0 : $scriptPath = PATH_TO_ROOT."literatur/literatur.php";
418 0 : $commentPage = Data::toHTML($com["CommentPage"], false);
419 0 : eval($this->commentTemplate->GetTemplate());
420 0 : }
421 0 : }
422 0 : }
423 :
424 : // ----------------------------------- Hilfsfunktionen -----------------------------------
425 :
426 : /**
427 : * Vergleicht die Zeiteintraege von zwei Literaturempfehlungen
428 : *
429 : * @param $a object DB-Zeile eines Literatureintrags
430 : * @param $b object DB-Zeile eines Literatureintrags
431 : * @return bool true wenn Eintrag $b aelter ist als Eintrag $a, false sonst
432 : */
433 : public function literatureSort( $a, $b ) {
434 0 : return strtotime($a["Time"]) < strtotime($b["Time"]);
435 : }
436 :
437 : /**
438 : * Gibt einen String zurück, nach dem die Literatur sotiert wird
439 : * Sortiert wird nacheinander nach UserGroup, Settings und Titel
440 : *
441 : * @param $obj object DB-Zeile eines Literatureintrags
442 : * @return string
443 : */
444 : public function literatureDefaultSortString( $obj ) {
445 0 : switch ( $obj->UserGroup ) {
446 0 : case 2: $sortuser = "3"; break;
447 0 : case 3: $sortuser = "2"; break;
448 0 : default: $sortuser = strval( $obj->UserGroup );
449 0 : }
450 0 : $sortsettings = "0000";
451 0 : for ($i=0;$i<4;$i++) {
452 0 : $sortsettings[$i] = ($obj->Settings[$i] == '1') ? '0' : '1';
453 0 : }
454 0 : return $sortuser . $sortsettings . $obj->Title;
455 : }
456 :
457 : /**
458 : * Vergleicht zwei Literatureintraege
459 : *
460 : * @param $a object DB-Zeile eines Literatureintrags
461 : * @param $b object DB-Zeile eines Literatureintrags
462 : * @return int 0 wenn die Eintraege gleich sind, ansonsten einen Wert !=0
463 : */
464 : public function literatureCompare( $a, $b ) {
465 0 : if ( isset($_SESSION['course']) && $_SESSION['course'] == 0 ) {
466 0 : return strtotime( $a->Time ) < strtotime( $b->Time );
467 : }
468 0 : $aval = self::literatureDefaultSortString( $a );
469 0 : $bval = self::literatureDefaultSortString( $b );
470 0 : return strcmp( $aval, $bval );
471 : }
472 :
473 : /**
474 : * Liefert die Position der Literatur-ID im Array
475 : *
476 : * @param $books array Liste der Literatureintraege
477 : * @param $id int ID des gesuchten Literatureintrags
478 : * @param $type char Literaturtyp ('B' oder 'L')
479 : * @return int mixed
480 : */
481 : public function literaturePosition( $books, $id, $type ) {
482 0 : for ( $i=0; $i<count($books); $i++ ) {
483 0 : if ($books[$i]->ID == $id && isset( $books[$i]->LitType ) && $books[$i]->LitType == $type ) {
484 0 : return $i;
485 : }
486 0 : }
487 0 : return null;
488 : }
489 :
490 : /**
491 : * Liefert die Position der Kommentar-ID im Array
492 : *
493 : * @param $comment array Liste der Kommentare
494 : * @param $id int ID des gesuchten Kommentars
495 : * @param $type char Literaturtyp ('B' oder 'L')
496 : * @return int mixed
497 : */
498 : public function literatureCommentPosition( $comment, $id, $type ) {
499 0 : for ( $i=0; $i<count($comment); $i++ ) {
500 0 : if ( $comment[$i]->ID == $id && $comment[$i]->LitTyp == $type ) {
501 0 : return $i;
502 : }
503 0 : }
504 0 : return null;
505 : }
506 :
507 : /**
508 : * Berechnet die Literatur-Seitenzahl
509 : * Wenn es Kommentare gibt, dann gib die Funktion den nullbasierten Seitenindex zurueck.
510 : * Ansonsten 0.
511 : *
512 : * @param $litcount int Gesamtanzahl der anzuzeigenden Literatureintraege
513 : * @param $itemsperpage int Anzahl der anzuzeigenden Literatureintraege pro Seite (default: 10)
514 : * @return int
515 : */
516 : public function literaturePageNum( $litcount, $itemsperpage = 10) {
517 0 : $pagenum = ceil( $litcount / $itemsperpage );
518 0 : if ( $pagenum > 0 && (($litcount % $itemsperpage) > 0) ) {
519 0 : $pagenum -= 1;
520 0 : }
521 0 : return $pagenum;
522 : }
523 :
524 : }
|